<?php

namespace app\admin\validate;

use think\Validate;

class Invoice extends Validate
{
    // 验证规则
    protected $rule = [
        'id'                => 'require|integer',
        'invoice_no'        => 'require|max:100',
        'applicant'         => 'require|integer',
        'customer_id'       => 'require|integer',
        'order_id'          => 'require',
        'invoicing_date'    => 'require|date',
        'tax_refund'        => 'require|in:0,1',
        'taxrefund_amount'  => 'requireIf:tax_refund,1|float',
        'invoice_amount'    => 'require|float',
        'payment_ids'       => 'require|max:1000',
        'invoice_type'      => 'require|in:1,2',
        'remark'            => 'max:500',
        'attach'            => 'max:1000',
        'invoice_attach'    => 'max:1000',
        'invoice_header'    => 'max:100',
        'tax_id_num'        => 'max:100',
        'register_phone'    => 'max:100',
        'billing_address'   => 'max:255',
        'opening_bank'      => 'max:100',
        'opening_account'   => 'max:100',
    ];

    // 错误信息
    protected $message = [
        'id.require'                   => 'id不能为空',
        // 'invoice_no.require'           => '发票编号不能为空',
        'invoice_no.max'               => '发票编号不能超过100个字符',
        'invoice_no.unique'            => '发票编号已存在',
        'applicant.require'            => '申请人不能为空',
        'applicant.integer'            => '申请人必须为整数',
        'customer_id.require'          => '关联客户不能为空',
        'customer_id.integer'          => '关联客户必须为整数',
        'order_id.require'             => '关联订单不能为空',
        'invoicing_date.require'       => '开票日期不能为空',
        'invoicing_date.date'          => '开票日期格式不正确',
        'tax_refund.require'           => '是否退税不能为空',
        'tax_refund.in'                => '退税类型无效',
        'taxrefund_amount.requireIf'   => '退税金额不能为空',
        'taxrefund_amount.float'       => '退税金额必须为数字',
        'invoice_amount.require'       => '开票金额不能为空',
        'invoice_amount.float'         => '开票金额必须为数字',
        'payment_ids.require'          => '付款单ID不能为空',
        'payment_ids.max'              => '付款单ID长度不能超过1000个字符',
        'invoice_type.require'         => '发票类型不能为空',
        'invoice_type.in'              => '发票类型无效',
        'remark.max'                   => '备注不能超过500个字符',
        'attach.max'                   => '附件长度不能超过1000个字符',
        'invoice_attach.max'           => '发票附件长度不能超过1000个字符',
        'invoice_header.max'           => '发票抬头不能超过100个字符',
        'tax_id_num.max'               => '纳税识别号不能超过100个字符',
        'register_phone.max'           => '注册电话不能超过100个字符',
        'billing_address.max'          => '开票地址不能超过255个字符',
        'opening_bank.max'             => '开户行不能超过100个字符',
        'opening_account.max'          => '开户账号不能超过100个字符',
    ];

    // 验证场景
    protected $scene = [
        'create' => ['invoice_no', 'applicant', 'customer_id', 'order_id',  'invoicing_date', 'tax_refund', 'taxrefund_amount', 'invoice_amount', 'payment_ids', 'invoice_type', 'remark', 'attach', 'invoice_attach', 'invoice_header', 'tax_id_num', 'register_phone', 'billing_address', 'opening_bank', 'opening_account'],
        'update' => ['id', 'invoice_no', 'applicant', 'customer_id', 'order_id',  'invoicing_date', 'tax_refund', 'taxrefund_amount', 'invoice_amount', 'payment_ids', 'invoice_type', 'remark', 'attach', 'invoice_attach', 'invoice_header', 'tax_id_num', 'register_phone', 'billing_address', 'opening_bank', 'opening_account'],
        'delete' => ['is_del'],
        'cancel' => ['id'],
    ];
}
